#include "response.h"




namespace dxy::easyWebServer
{

Response::Response(int fd)
    : m_cliFd(fd)
{

}

Response::~Response()
{

}

void Response::setHead(const std::string & version, const std::string & httpCode)
{
    m_head = version + " " + httpCode + "\r\n";
}

void Response::add(const std::string & key, const std::string & value)
{
    m_ctx.push_back(key + ": " + value + "\r\n");
}

void Response::addContext(const std::string & src)
{
    m_body = src;
}

void Response::send()
{
    m_conn.sendMsg(m_cliFd, m_head);
    for(auto it = m_ctx.begin(); it != m_ctx.end(); it++)
    {
        m_conn.sendMsg(m_cliFd, *it);
    }
    m_conn.sendMsg(m_cliFd, "\r\n");
    m_conn.sendMsg(m_cliFd, m_body);
}





}

